using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using server.Extensions;
namespace server.Models;

public class UserToken
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public long ID { get; set; }=DateTime.Now.Ticks;
    public int UserID { get; set; }
    // public long Token { get; set; }
    public DateTime ExpireDate { get; set; }
    public Right Right { get; set; }

    public bool IsOutdated(){
        return DateTime.Now > ExpireDate;
    }

    [NotMapped]
    public TimeSpan MaxAge { get; set; }=TimeSpan.FromDays(7);

    public UserToken(User user)
    {
        UserID=user.ID;
        ExpireDate=DateTime.Now+MaxAge;
        Right=user.Role.Right;
    }

    public UserToken()
    {
        
    }
}